package com.ruoyi.linkage.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.ruoyi.linkage.Vo.LinkageStrategyVo;
import com.ruoyi.linkage.domain.LinkageAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.linkage.mapper.LinkagePlcConfMapper;
import com.ruoyi.linkage.domain.LinkagePlcConf;
import com.ruoyi.linkage.service.ILinkagePlcConfService;

/**
 * 单机PLC控制逻辑配置Service业务层处理
 *
 * @author pengjie
 * @date 2023-12-20
 */
@Service
public class LinkagePlcConfServiceImpl implements ILinkagePlcConfService
{
    @Autowired
    private LinkagePlcConfMapper linkagePlcConfMapper;

    /**
     * 查询单机PLC控制逻辑配置
     *
     * @param id 单机PLC控制逻辑配置主键
     * @return 单机PLC控制逻辑配置
     */
    @Override
    public LinkagePlcConf selectLinkagePlcConfById(Long id)
    {
        return linkagePlcConfMapper.selectLinkagePlcConfById(id);
    }

    /**
     * 查询单机PLC控制逻辑配置列表
     *
     * @param linkagePlcConf 单机PLC控制逻辑配置
     * @return 单机PLC控制逻辑配置
     */
    @Override
    public List<LinkagePlcConf> selectLinkagePlcConfList(LinkagePlcConf linkagePlcConf)
    {
        return linkagePlcConfMapper.selectLinkagePlcConfList(linkagePlcConf);
    }

    @Override
    public PageInfo<LinkagePlcConf> selectPage(LinkageStrategyVo linkageStrategyVo) {
        IPage<LinkagePlcConf> page = new Page<>(Integer.parseInt(linkageStrategyVo.getPageNum()),Integer.parseInt(linkageStrategyVo.getPageSize()));
        String str=linkageStrategyVo.getColumn();
        //修改驼峰命名为数据库列格式
        StringBuffer buf=new StringBuffer();
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (Character.isUpperCase(c)) {
                buf.append('_');
                buf.append(Character.toLowerCase(c));
            }else {
                buf.append(c);
            }
        }
        linkageStrategyVo.setColumn(buf.toString());
        List<LinkagePlcConf> list=linkagePlcConfMapper.selectListOrder(linkageStrategyVo);
        PageInfo<LinkagePlcConf> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 新增单机PLC控制逻辑配置
     *
     * @param linkagePlcConf 单机PLC控制逻辑配置
     * @return 结果
     */
    @Override
    public int insertLinkagePlcConf(LinkagePlcConf linkagePlcConf)
    {
        return linkagePlcConfMapper.insertLinkagePlcConf(linkagePlcConf);
    }

    /**
     * 修改单机PLC控制逻辑配置
     *
     * @param linkagePlcConf 单机PLC控制逻辑配置
     * @return 结果
     */
    @Override
    public int updateLinkagePlcConf(LinkagePlcConf linkagePlcConf)
    {
        return linkagePlcConfMapper.updateLinkagePlcConf(linkagePlcConf);
    }

    /**
     * 批量删除单机PLC控制逻辑配置
     *
     * @param ids 需要删除的单机PLC控制逻辑配置主键
     * @return 结果
     */
    @Override
    public int deleteLinkagePlcConfByIds(Long[] ids)
    {
        return linkagePlcConfMapper.deleteLinkagePlcConfByIds(ids);
    }

    /**
     * 删除单机PLC控制逻辑配置信息
     *
     * @param id 单机PLC控制逻辑配置主键
     * @return 结果
     */
    @Override
    public int deleteLinkagePlcConfById(Long id)
    {
        return linkagePlcConfMapper.deleteLinkagePlcConfById(id);
    }
}
